/*
异步调用数据库读写
*/
const mysql = require("mysql")

const path = require("path")

const Genid = require("../utils/SnowFlake.js")
const config = require("../config/config.js");

var db = mysql.createConnection(config.db)
var genid = new Genid({ WorkerId: 1 })

db.async = {}

// 数据库封装
db.async.query = (sql, params, level=1) => {
	return new Promise(
		(resolve, reject) => {
			// console.log(sql);
			// console.log(params);
			db.query(sql, params, (err, rows) => {
				// console.log(rows);
				resolve({ err, rows })
			})
		}
	)
}


module.exports = { db, genid }
